import { articleOneApi } from "apis";
import { Component } from "react";
import Article from "src/component/Article";

export default class ArticlePage extends Component {
	constructor(props) {
		super(props);
		this.state = {
			markdown: "# 正在加载 。。。",
		};
	}

	componentDidMount() {
		// 获取文章数据
		const _this = this;
		const article_id = this.props.match.params.id;
		articleOneApi(article_id)
			.then(function (res) {
				_this.setState({
					markdown: res.data.content,
				});
			})
			.catch(function (error) {
				_this.setState({
					markdown: "# " + error,
				});
			});
	}

	render() {
		return (
			<div className="article-page">
				<Article markdown={this.state.markdown} />
			</div>
		);
	}
}
